<template>
    <!--    <div>载体</div>-->
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
            <el-form-item label="任务状态" prop="status">
                <el-select v-model="queryParams.status" placeholder="请选择任务状态">
                    <el-option label="已完成" value="2"></el-option>
                    <el-option label="巡检中" value="1"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="日期">
                <el-date-picker v-model="valueTime" type="daterange" range-separator="至" start-placeholder="开始日期"
                    end-placeholder="结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="任务名称" prop="taskName">
                <el-input v-model="queryParams.taskName" placeholder="请输入任务名称" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>

            <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8" ref="refbut">

            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table ref="table" v-loading="loading" :data="dataList" :height="tableHeight"
            @selection-change="handleSelectionChange" border stripe>
            <el-table-column label="序号" sortable align="center" type="index" prop="id" />
            <!-- 2 已完成  1 巡检中 -->
            <el-table-column label="任务状态" prop="status" align="center" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    {{ scope.row.status == "2" ? '已完成' : '巡检中' }}
                </template>
            </el-table-column>
            <el-table-column label="任务名称" prop="taskName" align="center" :show-overflow-tooltip="true" />
            <el-table-column label="开始时间" prop="startTime" align="center" :show-overflow-tooltip="true" />
            <el-table-column label="结束时间" prop="endTime" align="center" :show-overflow-tooltip="true" />
            <el-table-column label="简略数据" prop="message" align="center" :show-overflow-tooltip="true" />
<!--            <el-table-column label="备注" prop="remark" align="center" :show-overflow-tooltip="true" />-->
            <el-table-column label="操作" align="center" width="300">
                <template slot-scope="scope">
                    <el-button plain type="success" size="mini" @click="handleDetail(scope.row)">查看详情</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />

        <indexDetail v-if="isOpen" :isOpen="isOpen" :row="row" @closeDelDialog="closeDelDialog"></indexDetail>
    </div>
</template>

<script>
import estimateTableHeight from "@/mixins/estimateTableHeight";
import { inspectionLogList } from '@/api/cqbc/inspectionData/inspectionLog.js'
import indexDetail from "@/views/cqbc/inspectionData/inspectionLog/indexDetail.vue"

export default {
    mixins: [estimateTableHeight], // 混入方法
    archive_Dicts: ['CARRIER_TYPE'],
    components: {
        indexDetail
    },
    data() {
        return {
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            dataList: [],
            total: 0,
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                taskName: undefined,
                status: undefined,

            },
            valueTime: undefined,
            Id: undefined,
            isOpen: false,
            row: ""

        }
    },
    created() {
        this.getList()
    },
    methods: {
        getList() {
            inspectionLogList(this.queryParams).then(response => {
                this.dataList = response.rows
                this.total = response.total
                this.loading = false
            })
        },
        handleQuery() {
            if (this.valueTime != undefined) {
                this.queryParams['startTime'] = this.valueTime[0];
                this.queryParams['endTime'] = this.valueTime[1];
            }else{
                this.queryParams['startTime'] =undefined;
                this.queryParams['endTime'] = undefined;
            }

            this.getList();
        },
        resetQuery() {
            this.valueTime = undefined
            this.queryParams = {
                pageNum: 1,
                pageSize: 10,
                taskName: undefined,
                startTime: undefined,
                endTime: undefined,
                status: undefined
            },
                this.getList();
        },
        table_index(index) {
            return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },


        //查看详情
        handleDetail(row) {
            var that = this;
            this.row = row;
            this.isOpen = true;
        },
        closeDelDialog() {
            this.isOpen = false;
        },
    }
}
</script>

<style></style>
